package com.riverstar.wwndemo.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ImageBundle;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.ImageBundle.Resource;

public class TopPanel extends Composite implements ClickHandler{

	public interface Images extends ImageBundle {
		@Resource("loading.gif")
		AbstractImagePrototype loading();
	}
	
	private HTML signOutLink = new HTML("<a href='javascript:;'>Sign Out</a>");
	private HTML aboutLink = new HTML("<a href='javascript:;'>About</a>");
	private HorizontalPanel outer = new HorizontalPanel();
	private VerticalPanel inner = new VerticalPanel();

	private int topPanel_height;
	
	public TopPanel(Images images) {		
		outer.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT);
		inner.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		inner.setVerticalAlignment(VerticalPanel.ALIGN_TOP);

		inner.setWidth("100%");
		Image loading = images.loading().createImage();
		
		MenuBar menu = new MenuBar();
	    menu.setAutoOpen(true);
	    menu.setWidth("100%");
	    menu.setAnimationEnabled(true);

		MenuBar fileMenu = new MenuBar(true);
		fileMenu.setAnimationEnabled(true);
		fileMenu.addSeparator();


		menu.addItem(new MenuItem("File Menu",fileMenu));
		
		final String space = "&nbsp;";
		

		HorizontalPanel links = new HorizontalPanel();
		links.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		links.setVerticalAlignment(VerticalPanel.ALIGN_TOP);
		
		links.setSpacing(4);
	    links.add(signOutLink);
	    links.add(aboutLink);

	    outer.add(menu);

	    signOutLink.addClickHandler(this);
	    aboutLink.addClickHandler(this);
	    inner.add(new HTML("Welcome back, foo@example.com"));
	    inner.add(links);
	    inner.add(new HTML(space));
	    
	    inner.getWidget(0).setStyleName("topPanel_welcome");
	    inner.getWidget(1).setStyleName("topPanel_links");
	    inner.getWidget(2).setStyleName("topPanel_space");

	    inner.setStyleName("topPanel_inner");

	    outer.add(inner);
	    topPanel_height = 50;
	    initWidget(outer);
	}
	
	@Override
	public void onClick(ClickEvent event) {
		Object sender = event.getSource();
		
	}

	public void adjustSize(int width, int height) {
		//this.outer.setPixelSize(width, height);//.setWidth(String.valueOf(width));
		this.inner.setPixelSize(200, topPanel_height);//.setWidth(String.valueOf(width));
	}

	public int getHeight() {
		return topPanel_height;
	}

}
